fix(typegen): escape Go struct tags - #1127
Closed
hsusul wants to merge 1 commit into
Closed
Conversation
Signed-off-by: Henry Su <henrysu4707@gmail.com>
Contributor
|
Thank you for the contribution! postgres-meta's type generation is moving to the shared |
spydon
added a commit
to supabase/sdk
that referenced
this pull request
Sep 1, 2026
… names Go struct tags were interpolated into raw string literals verbatim, so a column name containing a backtick terminated the literal early and the generated source failed to parse. Names containing double quotes or backslashes compiled but produced tags that reflect.StructTag could not round-trip. Column and composite attribute names are now quoted with JSON.stringify, whose escape sequences are a subset of Go's, so reflect.StructTag.Get recovers the exact name. Ordinary names keep their previous raw literal representation; only names containing a backtick fall back to an interpreted literal, since Go raw literals cannot contain one. Validated against the Go toolchain: generated structs for names with backticks, quotes, backslashes and control characters parse under gofmt and round-trip through reflect.StructTag.Get. Ported from supabase/postgres-meta#1127 and supabase/postgres-meta#1131.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
PostgreSQL quoted identifiers can contain backticks. The Go generator interpolated column names directly into raw struct-tag literals, so a name containing a backtick terminated the literal and produced source that
gofmtrejected.Root cause
Both table-column and composite-attribute paths emitted
jsontags without escaping the database-provided name or accounting for the raw literal delimiter.Solution
Build the
jsontag value with JSON-compatible quoting. Continue using the current raw Go literal when possible, and emit an interpreted Go literal when the value contains a backtick.Tests and validation
npx vitest run test/server/templates/go.test.ts— 6 passedgofmt— passednpm run check— passednpm run build— passednpx prettier --check src/server/templates/go.ts test/server/templates/go.test.ts— passedgit diff --check— passedorigin/master, while the oversized-result timeout passed on the untouched baselineCompatibility and risk
Ordinary generated tags retain their previous representation. The change is limited to tag serialization and does not alter field naming or Go type mapping.
Documentation
No documentation change is needed because this restores valid generated output for supported PostgreSQL identifiers.
Fixes #1125